#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;

class Solution
{
public:
    string reverseStr(string s, int k)
    {
        int n = s.size();
        if (n <= k)
        {
            reverse(s.begin(), s.end());
            return s;
        }
        for (int i = 0;i < n;i += 2 * k)
        {
            int left = i, right = i + k - 1;
            if (right > n)
                right = n - 1;
            while (left <= right)
            {
                swap(s[left], s[right]);
                left++;
                right--;
            }
        }
        return s;
    }
};

int main()
{
    string s("abcdefg");
    Solution c;
    cout << c.Solution::reverseStr(s, 8);
    return 0;
}
